package ua.com.softway.date.benchmark;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Random;

import junit.framework.Assert;
import ua.com.softway.date.Date;

/**
 * Test if date calculations are same as in gregorian calendar
 */
public class TestCalendarCalculation {
    public static void main(String[] args) {
        int ops = 3000000;
        
        Random random = new Random();
        
        for (int i = 0; i < ops; i ++) {
            int year = 5 + random.nextInt(2000);
            int month = 25 - random.nextInt(50);
            int day = 50 - random.nextInt(100);
            
            GregorianCalendar calendar = new GregorianCalendar(year, month, day);
            Date date = new Date(year, month + 1, day);
            
            if (date.getYear() == 1582) continue; // skip
            
            String s = "Failed on y=" + year + ",m=" + month + ",d=" + day + ", i=" + i;
            
            Assert.assertEquals(s, calendar.get(Calendar.YEAR), date.getYear());
            Assert.assertEquals(s, calendar.get(Calendar.MONTH) + 1, date.getMonth());
            Assert.assertEquals(s, calendar.get(Calendar.DAY_OF_MONTH), date.getDay());
        }
    }
}
